package cn.itcast.bos.service.transit.impl;

import cn.itcast.bos.dao.take_delivery.WayBillRepository;
import cn.itcast.bos.dao.transit.SignInfoRepository;
import cn.itcast.bos.dao.transit.TransitInfoRepository;
import cn.itcast.bos.domain.take_delivery.WayBill;
import cn.itcast.bos.domain.transit.SignInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.index.WayBillIndexRepository;
import cn.itcast.bos.service.transit.SignInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SignInfoServiceImpl implements SignInfoService {

    @Autowired
    private SignInfoRepository signInfoRepository;
    @Autowired
    private TransitInfoRepository transitInfoRepository;
    @Autowired
    private WayBillIndexRepository wayBillIndexRepository;
    @Autowired
    private WayBillRepository wayBillRepository;

    @Override
    public void save(SignInfo model, String transitInfoId) {
        TransitInfo transitInfo = transitInfoRepository.findOne(Integer.parseInt(transitInfoId));
        transitInfo.setSignInfo(model);
        WayBill wayBill = transitInfo.getWayBill();
        if ("正常".equals(model.getSignType())) {
            transitInfo.setStatus("正常签收");
            wayBill.setSignStatus(3);
        } else {
            transitInfo.setStatus("异常");
            wayBill.setSignStatus(4);
        }
        signInfoRepository.save(model);
        wayBillRepository.save(wayBill);
        wayBillIndexRepository.save(wayBill);
        transitInfoRepository.save(transitInfo);
    }
}
